module.exports = options => async (req, res, next) => {
  const AdminUser = require('../models/AdminUser')
  const jwt = require('jsonwebtoken')
  const assert = require('http-assert')

  const token = String(req.headers.authorization || '').split(' ').pop()

  assert(token, 401, "token 不存在")
  const { id } = jwt.verify(token, req.app.get('secret'))
  assert(id, 401, "token 无效")
  req.user = await AdminUser.findById(id)
  assert(req.user, 401, "请先登录")

  console.log(req.user)
  await next()
}